package pt.iscte.pcd.avioes;
import java.util.Observable;


public class Aviao extends Observable implements Runnable {
	private int xi;
	private int yi;
	private int xf;
	private int yf;

	public Aviao(int xi, int yi, int xf, int yf) {
		super();
		this.xi = xi;
		this.yi = yi;
		this.xf = xf;
		this.yf = yf;
		setChanged(); // 1
		notifyObservers(null);
	}

	@Override
	public void run() {		
		while (true) {			
			move();
			setChanged(); // 1
			notifyObservers(null);
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
			}
		}
		
	}

	private void move() {
		int dx = xf - xi;
		int dy = yf - yi;
		//System.out.println("Move from " + xi + ", " + yi);
		xi += (int)Math.signum(dx);
		yi += (int)Math.signum(dy);
		//System.out.println("Move to " + xi + ", " + yi);
		
	}

	public int getX() {
		return xi;
	}

	public int getY() {
		return yi;
	}

}
